$(document).ready(function($) {
	var pageIndex = $(".pageIndex").text();  //当前页码
	var pages = $(".pages").text();   //页数
	var hasNext = $(".hasNext").text();   //是否有下一页(boolen)
	var nowPagesize = $(".pagesize").text();   //当前页记录数
	var pageMaxsize = $(".pageMaxsize").text();   //每页最多记录数
	var delete_url = $(".delete_url").text(); // 删除专辑的路径
	var reload_url = $(".reload_url").text(); //重新加载页面的路径
	var contextPath = $(".commonUrl").text();   //绝对路径
	var specialId=$(".specialId").text();    //专辑ID
	var pageIndexAddOne;
	//-------------------------分页-------------------------------------
	if (pages == 1) {
		$(".prev,.next").css("cursor", "default");
		$(".prev,.next").css("color", "rgb(166, 166, 166)");
		$(".prev,.next").removeAttr('href');
	} else {
		if (hasNext == "false") {
			$(".next").css("cursor", "default");
			$(".next").css("color", "rgb(166, 166, 166)");
			$(".next").removeAttr('href');
		}
		if (pageIndex == 1) {
			$(".prev").css("cursor", "default");
			$(".prev").css("color", "rgb(166, 166, 166)");
			$(".prev").removeAttr('href');
		}
	}
	for (var i = 1; i < pages;) {
		var result = "";
		i = i + 1;
		result += "<option" + " value=" + "'" + i + "'" + " >" + "第" + i + "页" + "</option>";
		$(".pageNum").append(result);
	}
	$(".pageNum option[value="+pageIndex+ "]").attr("selected",true);
	$(".pageNum").change(function() {
		var selectedPageNum=$(".pageNum").val();
		location.href = contextPath+reload_url+"?id="+specialId+"&pageindex=" + selectedPageNum + "&pagesize="+pageMaxsize;
	})
	$(".prev").click(function(){
		location.href = contextPath+reload_url+"?id="+specialId+"&pageindex=" + (pageIndex-1) + "&pagesize="+pageMaxsize;
	})
	$(".next").click(function(){
		pageIndex++;
		location.href = contextPath+reload_url+"?id="+specialId+"&pageindex=" + pageIndex + "&pagesize="+pageMaxsize;
	})
	//--------------------删除和增加图标出现效果--------------------------
	$(".special").each(function(index) {
		$(".special").eq(index).mouseover(function() {
				$(".special_right").eq(index).slideDown(200);
		})
		$(".special").eq(index).mouseleave(function() {
				$(".special_right").eq(index).slideUp(200);
		})
	})
		//---------------------------删除---------------------------------
	$('.delete').each(function(index) {
		$('.delete').eq(index).click(function() {
			$('.body-delete').fadeIn(100); //全局变得黑的效果
			$('.hide-body-delete').slideDown(200); //将隐藏的窗口div显示出来 
			design_id = $(".design_id").eq(index).val();
		})
	});
	$('.close-delete').click(function() {
		$('.body-delete').fadeOut(100);
		$('.hide-body-delete').slideUp(200); //将显示的窗口隐藏起来 
	});
		$('.delbtn').click(function() {
			$('.body-delete').fadeOut(100);
			$('.hide-body-delete').slideUp(200);
			if(nowPagesize==1){
				if(pageIndex!=1){     
					pageIndexDelOne=pageIndex-1;
				}
			}else{
				pageIndexDelOne=pageIndex;
			}
			$.ajax({
				url: contextPath+delete_url,
				data: "id=" + design_id,
				success: function(data) {
					alert("删除成功！");
					location.href = contextPath+reload_url+"?id="+specialId+"&pageindex=" + pageIndexDelOne + "&pagesize="+pageMaxsize;
				},
				error: function(e) {
					alert("删除失败，请重新操作！");
				}
			})
	});
})